package com.sgroupware.modules.car.action;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.opensymphony.xwork2.Preparable;
import com.simpleframe.web.action.CrudActionSupport;
import com.sgroupware.modules.car.CarInfor;
import com.sgroupware.modules.car.service.CarInforService;

@Scope("prototype")
@Namespace("/carInfor")
@Action("/carInfor/carInfor")
public class CarInforAction extends CrudActionSupport  {
	@Autowired
	private CarInforService carInforService;
	private CarInfor carInfor;

	@Override
	public String main(){
		return MAIN;
	}
	
	@Override
	public String grid() throws Exception {
		page = carInforService.getPage(getSearcher());
		return GRID;
	}
	
	@Override
	public String create() throws Exception {
		setSaveMode();
		carInfor = new CarInfor();
		
		return EDIT;
	}
	
	@Override
	public String edit() throws Exception {
		setUpdateMode();
		carInfor = carInforService.getById(carInfor.getId());
		return EDIT;
	}
	
	@Override
	public String save() throws Exception {
		carInforService.create(carInfor);
		return success("添加成功");
	}
	
	public String update() throws Exception {
		
		carInforService.update(carInfor);
		return success("修改成功");
	}
	
	protected void prepareUpdate() throws Exception {
		carInfor = carInforService.getById(getId());
	}
	
	public void validator() throws Exception {
		System.out.println("执行验证");
	}
	
	@Override
	public String delete() throws Exception {
		carInforService.deletes(ids);
		addMessage("删除成功");
		return null;
	}
	
	//setters and getters
	
	public void setCarInfor(CarInfor carInfor) {
		this.carInfor = carInfor;
	}
	
	public CarInfor getCarInfor() {
		return carInfor;
	}
}
